﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TanHuan.Authorize.Model;
using TanHuan.Authorize.Common;

namespace TanHuan.Authorize.DataAccess
{
    public class AuthAppDA : DataAccessBase
    {
        /// <summary>
        /// 获取AuthApp
        /// </summary>
        /// <returns></returns>
        public List<AuthApp> GetAuthApp()
        {
            using (AuthorizeDBEntities db = new AuthorizeDBEntities())
            {
                return db.AuthApp.ToList();
            }
        }

        /// <summary>
        /// 获取AuthApp
        /// </summary>
        /// <param name="pItem">分页实体</param>
        /// <returns></returns>
        public DataTable GetAuthApp(PageItem pItem)
        {
            pItem.SqlStr = "select *from AuthApp";
            pItem.PK = "Unid";
            return base.GetPageList(pItem);
        }

        /// <summary>
        /// 获取一个AuthApp实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AuthApp GetAuthAppById(int id)
        {
            using (AuthorizeDBEntities db = new AuthorizeDBEntities())
            {
                return db.AuthApp.SingleOrDefault(authApp => authApp.Unid == id);
            }
        }

        /// <summary>
        /// 创建一个AuthApp实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public void CreateAuthApp(AuthApp entity)
        {
            using (AuthorizeDBEntities db = new AuthorizeDBEntities())
            {
                db.AuthApp.Add(entity);
                db.SaveChanges();
            }
        }

        /// <summary>
        /// 删除一个AuthApp实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public void DeleteAuthApp(int id)
        {
            using (AuthorizeDBEntities db = new AuthorizeDBEntities())
            {
                AuthApp entity = db.AuthApp.SingleOrDefault(authApp => authApp.Unid == id);
                if (entity != null)
                {
                    db.AuthApp.Remove(entity);
                }
                db.SaveChanges();
            }
        }

        /// <summary>
        /// 修改一个AuthApp实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public void EditAuthApp(AuthApp entity)
        {
            using (AuthorizeDBEntities db = new AuthorizeDBEntities())
            {
                db.Entry(entity).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
        }
    }
}
